function SetTwoHandedProperty takes item weapon returns nothing
	local integer itemId = GetHandleId(weapon)
	local integer itemTypeId = GetItemTypeId(weapon)
	local real randomNumber = GetRandomExponential()
	local real weaponDamage = LoadReal(udg_ItemTypeDataHashTable , itemTypeId , StringHash("MEAN_DAMAGE"))
	local real rangeBouns = LoadReal(udg_ItemTypeDataHashTable , itemTypeId , StringHash("RANGE_BONUS"))
	local real bouns = randomNumber * weaponDamage * 0.5
	local string colorCode = null
	//--
	if weaponDamage > 0.0 then
		call SaveReal(udg_ItemDataHashTable , itemId , StringHash("MEAN_DAMAGE") , weaponDamage + bouns)
		if randomNumber > 0.5 then
			set colorCode = "0000FF00"
		else
			set colorCode = "00FFFFFF"
		endif
		call SaveStr(udg_ItemDataHashTable , itemId , StringHash("DAMAGE_BONUS_COLOR") , colorCode)
	endif
	
	if rangeBouns > 0.0 then
		set randomNumber = GetRandomExponential()
		set bouns = randomNumber * rangeBouns * 0.5
		call SaveReal(udg_ItemDataHashTable , itemId , StringHash("RANGE_BONUS") , rangeBouns + bouns)
		if randomNumber > 0.5 then
			set colorCode = "0000FF00"
		else
			set colorCode = "00FFFFFF"
		endif
		call SaveStr(udg_ItemDataHashTable , itemId , StringHash("RANGE_BONUS_COLOR") , colorCode)
	endif
	
	//--
	set colorCode = null
endfunction

function SetShieldProperty takes item shield returns nothing
	local integer itemId = GetHandleId(shield)
	local integer itemTypeId = GetItemTypeId(shield)
	local real randomNumber = GetRandomExponential()
	local real meanBlockProbability = LoadReal(udg_ItemTypeDataHashTable , itemTypeId , StringHash("BLOCK_PROBABILITY"))
	local real bouns = randomNumber * meanBlockProbability * 0.5
	local string colorCode = null
	//--
	if meanBlockProbability > 0.0 then
		call SaveReal(udg_ItemDataHashTable , itemId , StringHash("BLOCK_PROBABILITY") , meanBlockProbability + bouns)
		if randomNumber > 0.5 then
			set colorCode = "0000FF00"
		else
			set colorCode = "00FFFFFF"
		endif
		call SaveStr(udg_ItemDataHashTable , itemId , StringHash("BLOCK_PROBABILITY_BONUS_COLOR") , colorCode)
	endif
	//--
	set colorCode = null
endfunction

function SetDaggerProperty takes item dagger returns nothing
	local integer itemId = GetHandleId(dagger)
	local integer itemTypeId = GetItemTypeId(dagger)
	local real randomNumber = GetRandomExponential()
	local real meanDamage = LoadReal(udg_ItemTypeDataHashTable , itemTypeId , StringHash("MEAN_DAMAGE"))
	local real bouns = randomNumber * meanDamage * 0.5
	local string colorCode = null
	//--
	if meanDamage > 0.0 then
		call SaveReal(udg_ItemDataHashTable , itemId , StringHash("WEAPON_DAMAGE") , meanDamage + bouns)
		if randomNumber > 0.5 then
			set colorCode = "0000FF00"
		else
			set colorCode = "00FFFFFF"
		endif
		call SaveStr(udg_ItemDataHashTable , itemId , StringHash("DAMAGE_BONUS_COLOR") , colorCode)
	endif
	//--
	set colorCode = null
endfunction

function Trig_BuildItemFinished_Actions takes nothing returns nothing
	local unit trainedUnit = GetTrainedUnit()
	local integer unitType = GetUnitTypeId(trainedUnit)
	local integer itemType = LoadInteger(udg_BuildItemHashTable , unitType , 3)
	local item builtItem = CreateItem(itemType , GetUnitX(trainedUnit) , GetUnitY(trainedUnit))
	local integer weaponType = LoadInteger(udg_ItemTypeDataHashTable , itemType , StringHash("WEAPON_TYPE"))
	//--
	call KillUnit(trainedUnit)
	call RemoveUnit(trainedUnit)
	call UnitAddItem(GetTriggerUnit() , builtItem)
	
	//鑄造者
	call SaveStr(udg_ItemDataHashTable , GetHandleId(builtItem) , StringHash("WEAPON_MAKER") , "鑄造者: " + udg_PlayerColors[GetPlayerId(GetOwningPlayer(trainedUnit))] + GetPlayerName(GetOwningPlayer(trainedUnit)) + "|r")
	
	//物品屬性
	if weaponType == StringHash("DAGGER") then
		call SetDaggerProperty(builtItem)
	elseif weaponType == StringHash("SHIELD") then
		call SetShieldProperty(builtItem)
	elseif weaponType == StringHash("TWO_HANDED") then
		call SetTwoHandedProperty(builtItem)
	endif
	//--
	set trainedUnit = null
	set builtItem = null
endfunction

function Trig_BuildItemFinishedTryAction takes nothing returns nothing
	if HaveSavedInteger(udg_BuildItemHashTable , GetUnitTypeId(GetTrainedUnit()) , 3) then
		call Trig_BuildItemFinished_Actions()
	endif
endfunction

function InitTrig_BuildItemFinished takes nothing returns nothing
	set gg_trg_BuildItemFinished = CreateTrigger()
	call TriggerRegisterAnyUnitEventBJ(gg_trg_BuildItemFinished , EVENT_PLAYER_UNIT_TRAIN_FINISH)
	call TriggerAddAction(gg_trg_BuildItemFinished , function Trig_BuildItemFinishedTryAction)
endfunction